package com.hgz.ssmdemo.web.controller;

import com.hgz.ssmdemo.common.BaseController;
import com.hgz.ssmdemo.common.ResultVO;
import com.hgz.ssmdemo.entity.User;
import com.hgz.ssmdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小志
 * @date 2025/6/25 - 15:23
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController extends BaseController {
    /**
     * 用户服务
     */
    private final UserService userService;

    @PostMapping("saveUser")
    public ResultVO<?> saveUser(@RequestBody User user){
        userService.saveUser(user);
        return success();
    }
    @PostMapping("deleteUser")
    public ResultVO<?> deleteUser(@RequestBody User user){
        userService.delete(user.getId());
        return success();
    }
    @PostMapping("updateUser")
    public ResultVO<?> updateUser(@RequestBody User user){
        userService.updateUser(user);
        return success();
    }
    @GetMapping("getUserById")
    public ResultVO<?> getUserById(@RequestParam("userId") Integer userId){
        return success(userService.getByUserid(userId));
    }
    @GetMapping("listUser")
    public ResultVO<?> listUser(){
        return success(userService.listUser());
    }
}
